package com.example.springtransaction.service;

import com.example.springtransaction.mapper.LogMapper;
import com.example.springtransaction.model.LogInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/5/8 13:39
 */
@Service
public class LogService {

    @Autowired
    private LogMapper logMapper ;
    @Transactional(propagation = Propagation.NESTED)
    public Integer add(LogInfo logInfo){
        Integer add = logMapper.add(logInfo);
        try {
            int num = 1/0;
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return add;
    }
}
